package me.yushuai.wukong.base.service;

import me.yushuai.wukong.base.api.dto.*;
import me.yushuai.wukong.common.dto.PageDTO;
import me.yushuai.wukong.common.exceptin.BizIdNotExistException;
import me.yushuai.wukong.common.exceptin.DuplicateBizIdException;
import me.yushuai.wukong.common.exceptin.NotExistException;
import me.yushuai.wukong.common.service.BaseService;

import java.time.LocalDate;
import java.util.Date;
import java.util.List;

/**
 * 配置管理业务接口类，
 *
 * @author zhoushuai@189.cn
 * @date 2022-09-14
 */
public interface ConfService extends BaseService {

    /**
     * 新建配置组
     *
     * @param dto 配置组信息
     * @return 返回配置组的物理Id
     * @throws DuplicateBizIdException 当业务Id已存在时抛出异常
     */
    Long createConfGroup(CreateConfGroupDTO dto) throws DuplicateBizIdException;

    /**
     * 更新配置组信息
     *
     * @param dto 配置组信息
     * @return 返回业务的组物料Id
     * @throws NotExistException 当配置组的物料Id不存在时抛出异常
     */
    Long updateConfGroup(UpdateConfGroupDTO dto) throws NotExistException;

    /**
     * 通过配置组Id删除配置组
     *
     * @param confGroupId 配置组Id
     * @throws NotExistException
     */
    void deleteConfGroupById(Long confGroupId) throws NotExistException;

    /**
     * 查询配置组的基本信息
     *
     * @param groupId 配置组
     * @return 返回配置组的基本信息
     * @throws NotExistException 当业务组Id不存在时抛出异常
     */
    ConfGroupDTO findConfGroupById(Long groupId) throws NotExistException;

    /**
     * 分页条件检索系统配置信息
     *
     * @param pagingSearchConfProfile 分页检索条件
     * @return 分页返回查询结果
     */
    PageDTO<ConfGroupDTO> pagingSearchConfGroup(PagingSearchConfGroup pagingSearchConfProfile);


    /**
     * 新建一条配置项信息
     *
     * @param dto 配置项信息
     * @return 返回配置项信息编号
     * @throws DuplicateBizIdException 当配置项已存在时抛出异常
     */
    Long createConf(CreateConfDTO dto) throws DuplicateBizIdException, NotExistException;

    /**
     * 更新配置所有信息，包规配置的定义信息
     *
     * @param dto 配置的定义信息及配置值
     * @return 返回配置的Id
     * @throws NotExistException 当配置的ID不存在时抛出异常
     */
    Long updateConfDef(UpdateConfDefDTO dto) throws NotExistException;

    /**
     * 修改配置项信息
     *
     * @param updateConfItemDTO 配置项信息
     * @return 返回修改后的配置项编号
     * @throws NotExistException 当配置项不存在时抛出异常
     */
    Long updateConf(UpdateConfValueDTO updateConfItemDTO) throws NotExistException;

    /**
     * 通过配置的业务Id查询配置的详细信息
     *
     * @param groupBizId 配置组的业务Id
     * @param confBizId  配置项的业务Id
     * @return 返回配置的详细信息
     * @throws BizIdNotExistException 当业务Id不存时抛出异常
     */
    ConfDTO findConfByBizId(String groupBizId, String confBizId) throws BizIdNotExistException;

    /**
     * It's compiler the value Of Conf and the expectValue, if two value are equal return true otherwise return false.
     *
     * @param groupBizId   配置文件所属组
     * @param confBizId    配置文件业务Id
     * @param defaultValue 配置文件的默认值
     * @param expectValue  配置文件的期望值
     * @return  if value of Conf and expectValue are equal return true otherwise return false.
     */
    boolean compareValue(String groupBizId, String confBizId, Object defaultValue, Object expectValue);

    /**
     * 比较两个值是否相等
     *
     * @param groupBizId  配置文件所属组
     * @param confBizId   配置文件业务Id
     * @param expectValue 配置文件期望结果
     * @return 返回true表示与期望值相同
     */
    boolean compareValue(String groupBizId, String confBizId, Object expectValue);

    /**
     * 与期望值比较，如果任何一个满足要求就表示相同
     *
     * @param groupBizId   配置文件所属组
     * @param confBizId    配置文件业务Id
     * @param expectValues 配置文件期望结果
     * @return 返回true表示与期望值相同
     */
    boolean compareValue(String groupBizId, String confBizId, Object[] expectValues);

    /**
     * 删除一条配置项信息
     *
     * @param groupId 配置编号
     * @param confId  配置项编号
     * @throws NotExistException 当配置项编码不存在时抛出异常
     */
    void deleteConf(Long groupId, Long confId) throws NotExistException;

    /**
     * 通过ID查询配置项的详细信息
     *
     * @param groupId 配置项编号
     * @param confId  配置项编号
     * @return 返回配置项的详细信息
     * @throws NotExistException 当配置项不存在时抛出异常
     */
    ConfDTO findConfById(Long groupId, Long confId) throws NotExistException;

    /**
     * get value of Conf and convert to {@link Boolean}, if the conf not exist or not support convert return the default value
     */
    Boolean boolValue(String groupBizId, String confBizId, Boolean defaultValue);

    /**
     * get value of Conf and convert to {@link Boolean}
     */
    Boolean boolValue(String groupBizId, String confBizId);

    /**
     * get value of Conf and convert it to {@link Integer} and return it.
     */
    Integer intValue(String groupBizId, String confBizId);

    /**
     * get value of Conf and convert to {@link Integer}, if the conf not exist or not support convert return the defaultValue
     */
    Integer intValue(String groupBizId, String confBizId, int defaultValue);

    /**
     * get value of Conf and convert it to {@link Long} and return
     */
    Long longValue(String groupBizId, String confBizId);

    /**
     * get value of Conf and convert it to {@link Long}, if the Conf not exists or not support convert return the defaultValue.
     */
    Long longValue(String groupBizId, String confBizId, long defaultValue);

    /**
     * get value of Conf and convert it to {@link String} and return.
     */
    String strValue(String groupBizId, String confBizId);

    /**
     * get value of Conf and convert it to {@link String}, if the conf not exists return the defaultValue.
     */
    String strValue(String groupBizId, String confBizId, String defaultValue);

    /**
     * get value of Conf and convert it to {@link Date} and return it.
     */
    Date dateValue(String groupBizId, String confBizId);

    /**
     * get value of Conf and convert it to {@link Date}, if the Conf not exists or not support convert return the defaultValue.
     */
    Date dateValue(String groupBizId, String confBizId, Date defaultValue);

    /**
     * get value of Conf and convert it to {@link Date} and return it.
     */
    LocalDate localDateValue(String groupBizId, String confBizId);

    /**
     * get value of Conf and convert it to {@link LocalDate}, if the Conf not exists or not support convert return the defaultValue.
     */
    LocalDate localDateValue(String groupBizId, String confBizId, LocalDate defaultValue);

    /**
     * get value of Conf and convert it to {@link java.time.LocalDateTime} return it.
     */
    LocalDate localDateTimeValue(String groupBizId, String confBizId);

    /**
     * get value of Conf and convert it to {@link java.time.LocalDateTime}, if the Conf not exists or not support convert return the defaultValue.
     */
    LocalDate localDateTimeValue(String groupBizId, String confBizId, LocalDate defaultValue);

    /**
     * get value of Conf if the conf not exists than throw exception.
     *
     * @param groupBizId the groupBizId of ConfGroup
     * @param confBizId  this confBizId of Conf
     * @param clazz      the class is want to class
     * @param <T>        the type is want to return
     * @return return value types' is <T>
     */
    <T> T findValue(String groupBizId, String confBizId, Class<T> clazz);

    /**
     * get value of Conf if the conf not exists or value convertor fail return defaultValue.
     *
     * @param groupBizId   the groupBizId is bizId of ConfGroup
     * @param confBizId    the confBizId is bizId of Conf
     * @param defaultValue when the value is null or convertor fail return default value.
     * @param clazz        the class is want to class
     * @param <T>          the type is want to return
     * @return return value type's is T
     */
    <T> T findValue(String groupBizId, String confBizId, T defaultValue, Class<T> clazz);

    /**
     * 分页条件检索配置项信息
     *
     * @param groupId          groupId of ConfGroup
     * @param pagingSearchConf 分页检索条件
     * @return 分页返回查询结果
     */
    PageDTO<ConfDTO> pagingSearchConf(Long groupId, PagingSearchConf pagingSearchConf);

    /**
     * 检查配置编号与配置项编码对应的配置项是否存在
     *
     * @param groupId   配置编号
     * @param confBizId 配置项编码
     * @return 当配置编码与配置项编码存在时返回true否则返回false
     */
    boolean checkExistsBizId(Long groupId, String confBizId);

    /**
     * 检查配置项编号是配置编号下的配置项
     *
     * @param groupId 配置编号
     * @param confId  配置项编号
     * @return 返回true表示配置项编码是配置编号下的配置项否则返回false
     */
    boolean checkExistsConfId(Long groupId, Long confId);

    /**
     * It's checking the groupBizId if exists, if exists return true otherwise return false
     *
     * @param groupBizId bizId of ConfGroup
     * @return return true the bizId exists otherwise return false
     */
    boolean checkExistsGroupBizId(String groupBizId);

    List<ConfDTO> findByConfGroupId(Long confGroupId);

    List<ConfDTO> findByConfGroupBizId(String confGroupBizId);

}
